package com.qzimp.fujiancuo.controller;

import com.mybatisflex.core.query.QueryWrapper;
import com.qzimp.fujiancuo.entity.Event;
import com.qzimp.fujiancuo.entity.vo.EentCuoVO;
import com.qzimp.fujiancuo.mapper.EventMapper;
import com.qzimp.fujiancuo.service.CuoService;
import com.qzimp.fujiancuo.service.EentCuoService;
import com.qzimp.fujiancuo.service.EventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/EventCuo")
@RequiredArgsConstructor
@Api(tags = "事件多表")
public class EentCuoController {

    final EentCuoService eentCuoService;
    final EventService eventService;
    final CuoService    cuoService;
    final EventMapper eventMapper;

    @GetMapping("slecet")
    @ApiOperation("查询所有厝及相关事件")
    public List<EentCuoVO> insertEentCuoVO(){
        return eentCuoService.selectEvenCuo();
    }

    @DeleteMapping("remove/{id}")
    @ApiOperation("根据主键删除相关事件")
    public String remove(@PathVariable Integer id) {
        // 先删除 tb_event 表中关联的记录
        QueryWrapper wrapper = QueryWrapper.create()
                .where(Event::getCuoId).eq(id);
        eventMapper.deleteByQuery(wrapper);

        // 再删除 tb_cuo 表中的记录
        cuoService.removeById(id);

        return "删除成功";
    }
}
